package com.ukao.pad.presenter;

import com.ukao.pad.base.BasePresenter;
import com.ukao.pad.bean.ReadBean;
import com.ukao.pad.bean.StoreInfoBean;
import com.ukao.pad.bean.UserInfoBean;
import com.ukao.pad.consts.Constant;
import com.ukao.pad.consts.SaveParamets;
import com.ukao.pad.retrofit.ApiCallback;
import com.ukao.pad.utils.T;
import com.ukao.pad.utils.ThreadUtils;
import com.ukao.pad.utils.Utils;
import com.ukao.pad.view.SelectStoresView;

import java.util.HashMap;

/**
 * Created by kefu001 on 2018/5/21.
 */

public class SelectStoresPresenter extends BasePresenter<SelectStoresView>{
    public SelectStoresPresenter(SelectStoresView view) {
        super.attachView(view);
    }

    /**
     * 接收门店信息
     */
  public void receiveStoreInfo(){
      mvpView.showLoading();
      HashMap mHashMap=new HashMap<String,String>();
      mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
      addSubscription(super.apiStores.queryStoresInfo(Constant.createParameter(mHashMap)),
              new ApiCallback<StoreInfoBean>() {
                  @Override
                  public void onSuccess(StoreInfoBean model) {
                      if (model.getHttpCode() == 200) {
                          mvpView.responseStoreInfoSuccess(model.getData());
                      }else{
                          mvpView.responseFail(model.getMsg());
                      }
                  }
                  @Override
                  public void onNoNewWork() {

                  }

                  @Override
                  public void onFinish() {
                      mvpView.hideLoading();
                  }

              });
  }

    /**
     *  请求用户的下单信息
     * @param StoreId
     * @param searchText
     */
    public  void requestUserOrdersInfo(String StoreId,String searchText){
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("storeId",StoreId);
        mHashMap.put("key",searchText);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        addSubscription(super.apiStores.queryPlaceOrder(Constant.createParameter(mHashMap)),
                new ApiCallback<UserInfoBean>() {
                    @Override
                    public void onSuccess(UserInfoBean model) {
                        if (model.getHttpCode()==200){
                            mvpView.responseUserInfoSuccess(model,searchText);
                        }else{
                            mvpView.responseFail(model.getMsg());
                        }
                    }
                    @Override
                    public void onNoNewWork() {

                    }
                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }
    /**
     *RFID
     */
    public void rfidSecret(final String rfidSecret   ) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mvpView.showLoading();
                HashMap     mHashMap=new HashMap<String,String>();
                mHashMap.put("rfidSecret",rfidSecret);
                mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
                addSubscription(apiStores.rfidSecret(Constant.createParameter(mHashMap)),
                        new ApiCallback<ReadBean>() {
                            @Override
                            public void onSuccess(ReadBean model) {

                                if (model.getHttpCode()==200){
                                    mvpView.responseRfrdSuccess(model);
                                }else{
                                    mvpView.responseFail(model.getMsg());
                                }
                            }

                            @Override
                            public void onNoNewWork() {
                            }

                            @Override
                            public void onFinish() {
                                mvpView.hideLoading();
                            }

                        });
            }
        });

    }

}
